package iq.native2ascii;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Process process = Runtime.getRuntime().exec(new String[]{"D:\\Program Files\\Java\\jdk1.6.0_20\\bin\\native2ascii.exe"});
			InputStreamReader ir = new InputStreamReader(process
					.getInputStream());
			LineNumberReader input = new LineNumberReader(ir);

			String line = null;
			while ((line = input.readLine()) != null) {
				System.out.println(line);
			}
			
			Test.exec("D:\\Program Files\\Java\\jdk1.6.0_20\\bin\\native2ascii.exe", new String[]{});
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private static boolean exec(String Cmd, String Input[]){
		boolean rc = false;
		try {
			Process porc = Runtime.getRuntime().exec(Cmd);
			PrintStream pout = new PrintStream(new BufferedOutputStream(porc.getOutputStream()));
			DataInputStream pin = new DataInputStream(new BufferedInputStream(porc.getInputStream()));
			DataInputStream perr = new DataInputStream(new BufferedInputStream(porc.getErrorStream()));
			if (Input != null) {
				for (int i = 0; i < Input.length; i++)
					pout.println(Input[i]);
				pout.flush();
			}
			while (perr.read() != -1) ;
			pout.close();
			pin.close();
			rc = true;
		} catch (IOException e){
		}
		return rc;
	}
	

}
